<?php

namespace App\Models;

use DB;
use Illuminate\Database\Eloquent\Model;

class StayTime extends Model
{
    public $timestamps=false;
    protected $table='stay_time';
    protected $guarded = [];
    public static function getStayTime($scene_id=null){
        if($scene_id!=null){
            $stay = self::where('scene_id',$scene_id)->get(['time','percent']);
        }else{
            $stay = self::select('time', DB::raw('sum(percent) as total'))
                ->groupBy('time')
                ->get();
        }
        foreach ($stay as $val){
            $val->time=config('options.flow_stay')[$val->time];
        }
        return $stay;
    }
}